var util = require('../../utils/util.js');
const ttParse = require('../../ttParse/ttParse.js');
var app = getApp();

Page({
  data: {
    detailData: '',
    screen_w: 320,
    isIphone_X: false,
    showBtn: false 
  },

  onLoad: function (data) {
    var that = this;

    let dataType = "about"
    if (data.type) {
      dataType = data.type
    }

    this.setData({
      screen_w: app.screen_w,
      isIphone_x: app.isIphone_x,
      showBtn: dataType == "about"
    })

    if(dataType == "chongzhi") {
      that.getChongzhiXuzhi()
    } else {
      that.load(dataType)
    }

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  onShow: function () {

  },

  getChongzhiXuzhi: function (params) {
    tt.showLoading({
      title: '加载中',
      mask: 'true'
    });
    var that = this
    app.getUserInfo(util.orgid, function (res) {
      console.log("小程序信息：", res)
      tt.hideLoading()
      if (res.uid) {
        var detailMessage = "<div>" + res.intro + "</div>"
        ttParse.ttParse('messagehtml', 'html', detailMessage, that, 5)
      }
    })
  },

  load: function (typeStr) {
    tt.showLoading({
      title: '加载中',
      mask: 'true'
    });

    var that = this
    app.getAllAbout(typeStr, function (response) {
      console.log("协议信息：", response)
      tt.hideLoading()
      if (response && response.length > 0) {
        var detailMessage = "<div>" + response + "</div>";
        ttParse.ttParse('messagehtml', 'html', detailMessage, that, 5)
      }
    })

  },

  acceptAction: function () {
    let pages = getCurrentPages(); //获取所有页面栈实例列表
    let prevPage = pages[pages.length - 2]; //上一页页面实例
    prevPage.isReadedXieyi = true
    tt.navigateBack({ //tt.navigateTo跳转的返回，默认1为返回上一级
      delta: 1
    });
  }

})